namespace StockSharp.BusinessEntities;

/// <summary>
/// Own trade.
/// </summary>
[Serializable]
[DataContract]
[Display(
	ResourceType = typeof(LocalizedStrings),
	Name = LocalizedStrings.OwnTradeKey,
	Description = LocalizedStrings.OwnTradeDescKey)]
public class MyTrade : NotifiableObject
{
	/// <summary>
	/// Initializes a new instance of the <see cref="MyTrade"/>.
	/// </summary>
	public MyTrade()
	{
	}

	/// <summary>
	/// Order, for which a trade was filled.
	/// </summary>
	[DataMember]
	[TypeConverter(typeof(ExpandableObjectConverter))]
	[Display(
		ResourceType = typeof(LocalizedStrings),
		Name = LocalizedStrings.OrderKey,
		Description = LocalizedStrings.OwnTradeOrderKey,
		GroupName = LocalizedStrings.GeneralKey,
		Order = 0)]
	[BasicSetting]
	public Order Order { get; set; }

	/// <summary>
	/// Trade info.
	/// </summary>
	[DataMember]
	[TypeConverter(typeof(ExpandableObjectConverter))]
	[Display(
		ResourceType = typeof(LocalizedStrings),
		Name = LocalizedStrings.TradeKey,
		Description = LocalizedStrings.TickTradeInfoKey,
		GroupName = LocalizedStrings.GeneralKey,
		Order = 1)]
	public ITickTradeMessage Trade { get; set; }

	/// <summary>
	/// Commission.
	/// </summary>
	[DataMember]
	[Display(
		ResourceType = typeof(LocalizedStrings),
		Name = LocalizedStrings.CommissionKey,
		Description = LocalizedStrings.CommissionDescKey,
		GroupName = LocalizedStrings.CommissionKey,
		Order = 100)]
	public decimal? Commission { get; set; }

	/// <summary>
	/// Commission currency. Can be <see langword="null"/>.
	/// </summary>
	[Display(
		ResourceType = typeof(LocalizedStrings),
		Name = LocalizedStrings.CurrencyKey,
		Description = LocalizedStrings.CurrencyKey + LocalizedStrings.Dot,
		GroupName = LocalizedStrings.CommissionKey,
		Order = 101)]
	public string CommissionCurrency { get; set; }

	/// <summary>
	/// Slippage in trade price.
	/// </summary>
	[DataMember]
	[Display(
		ResourceType = typeof(LocalizedStrings),
		Name = LocalizedStrings.SlippageKey,
		Description = LocalizedStrings.SlippageTradeKey,
		GroupName = LocalizedStrings.StatisticsKey,
		Order = 1)]
	public decimal? Slippage { get; set; }

	private decimal? _pnL;

	/// <summary>
	/// The profit, realized by trade.
	/// </summary>
	[DataMember]
	[Display(
		ResourceType = typeof(LocalizedStrings),
		Name = LocalizedStrings.PnLKey,
		Description = LocalizedStrings.PnLKey + LocalizedStrings.Dot,
		GroupName = LocalizedStrings.StatisticsKey,
		Order = 2)]
	public decimal? PnL
	{
		get => _pnL;
		set
		{
			if (_pnL == value)
				return;

			_pnL = value;
			NotifyChanged();
		}
	}

	/// <summary>
	/// The position, generated by trade.
	/// </summary>
	[DataMember]
	[Display(
		ResourceType = typeof(LocalizedStrings),
		Name = LocalizedStrings.PositionKey,
		Description = LocalizedStrings.PositionKey + LocalizedStrings.Dot,
		GroupName = LocalizedStrings.StatisticsKey,
		Order = 2)]
	public decimal? Position { get; set; }

	/// <summary>
	/// Used to identify whether the order initiator is an aggressor or not in the trade.
	/// </summary>
	[Display(
		ResourceType = typeof(LocalizedStrings),
		Name = LocalizedStrings.InitiatorKey,
		Description = LocalizedStrings.InitiatorTradeKey,
		GroupName = LocalizedStrings.GeneralKey,
		Order = 3)]
	public bool? Initiator { get; set; }

	/// <summary>
	/// Yield.
	/// </summary>
	[DataMember]
	[Display(
		ResourceType = typeof(LocalizedStrings),
		Name = LocalizedStrings.YieldKey,
		Description = LocalizedStrings.YieldKey,
		GroupName = LocalizedStrings.GeneralKey,
		Order = 4)]
	public decimal? Yield { get; set; }

	/// <inheritdoc />
	public override string ToString()
	{
		return LocalizedStrings.TradeFromOrder.Put(Trade, Order);
	}
}